//  配置项目根路径
axios.defaults.baseURL = 'http://www.itcbc.com:8000'

//配置请求拦截器
axios.interceptors.request.use((config) => {
    const token = localStorage.getItem('token')
    if (token) {
        config.headers.Authorization = token
    }
    return config
}, (error) => {
    return Promise.reject(error)
})





//配置响应拦截器
axios.interceptors.response.use((response) => {
    const { code, message } = response.data
    if (code === 1) {
        //登录失败，弹出错误信息
        toastr.error(message)
    }
    //返回结果
    return response
}, (error) => {
    if (error.response.status === 401 && error.response.data.code === 1 && error.response.data.message === '身份验证失败') {
        //移除token
        localStorage.removeItem('token')
        location.href = './login.html'
    }
    return Promise.reject(error)
})